﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using IToursDataService;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;

namespace ToursDataService
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、svc 和配置文件中的类名“SysParameterCtrl”。
    public class SysParameterCtrl : ISysParameterCtrl
    {
        public string GetValueForKey(string key)
        {

            Database db = DatabaseFactory.CreateDatabase();

            DbCommand dbCommand;

            string sql = string.Format(@"SELECT [value] FROM sys_Parameter WHERE [key]='{0}'", key);

            dbCommand = db.GetSqlStringCommand(sql);

            object obj = db.ExecuteScalar(dbCommand);
            if (obj != null)
                return obj.ToString();
            else
                return "";

        }

        //public int UpdateValueForKey(string value, string key)
        //{
        //    Database db = DatabaseFactory.CreateDatabase();
        //    string sql = string.Format(@"UPDATE sys_Parameter SET [Value]='{0}' WHERE [Key]='{1}'", value, key);

        //    return db.ExecuteNonQuery(CommandType.Text, sql);
        //}
    }
}
